package com.chem.lems.controller;

import com.chem.lems.entity.Equipment;
import com.chem.lems.serves.EquipmentServies;
import com.chem.lems.utils.ResultUtil;
import com.chem.lems.vo.ApplyBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/equip")
public class EquipmentController {
    @Autowired
    private EquipmentServies equipmentServies;

    /**
     * 生成设备状态的枚举值,封装List返回前端
     *
     * @return
     */
    @GetMapping("states")
    public ResultUtil getEquipStates() {
        return equipmentServies.getEquipStatesEnum();
    }

    /**
     * 添加设备
     *
     * @param equipment
     * @return
     */
    @PostMapping()
    public ResultUtil addEquipment(@RequestBody Equipment equipment) {
        return equipmentServies.addEquipment(equipment);
    }

    /**
     * 获取全部用户列表 分页
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("{page}/{size}")
    public ResultUtil usersList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return equipmentServies.gitEquipByAll(page, size);
    }

    /**
     * 获取用户关联的全部设备列表
     * @param userId
     * @return
     */
    @GetMapping("userEquips/{userId}")
    public ResultUtil gitUserEquips(@PathVariable("userId") String userId) {
        return equipmentServies.gitUserEquips(userId);
    }

    /**
     * 模糊查询用户列表 分页
     *
     * @param equipName
     * @param page
     * @param size
     * @return
     */
    @GetMapping("{equipName}/{page}/{size}")
    public ResultUtil usersList(@PathVariable("equipName") String equipName, @PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return equipmentServies.gitEquipByNameLike(equipName, page, size);
    }


    /**
     * 根据设备名称查询设备信息
     *
     * @param equipId
     * @return
     */
    @GetMapping("{equipId}")
    public ResultUtil gitEquipInfoById(@PathVariable("equipId") String equipId) {
        return equipmentServies.gitEquipInfoById(equipId);
    }

    /**
     * 修改用户信息
     *
     * @param equipment
     * @return
     */
    @PutMapping()
    public ResultUtil editEquipInfo(@RequestBody Equipment equipment) {
        return equipmentServies.editEquipInfo(equipment);
    }

    /**
     * 删除设备
     *
     * @param equipId
     * @return
     */
    @DeleteMapping("{equipId}")
    public ResultUtil deleteById(@PathVariable("equipId") String equipId) {
        return equipmentServies.deleteById(equipId);
    }

    /**
     * 根据设备ID查询用户
     *
     * @param equipId
     * @return
     */
    @GetMapping("user/{equipId}")
    public ResultUtil getUserByEquipId(@PathVariable("equipId") String equipId) {
        return equipmentServies.getUserByEquipId(equipId);
    }

    /**
     * 设备的预约申请
     *
     * @param equipId
     * @return
     */
    @PutMapping("apply/{userId}/{equipId}")
    public ResultUtil applyEquip(@PathVariable("userId") String userId, @PathVariable("equipId") String equipId) {
        return equipmentServies.applyEquip(userId, equipId);
    }


    /**
     * 设备预约审核
     * @param applyBO
     * @return
     */
    @PutMapping("review")
    public ResultUtil applyReview(@RequestBody ApplyBO applyBO) {
        return equipmentServies.applyReview(applyBO);
    }

    /**
     * 获取需要审核的设备列表
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("record/{page}/{size}")
    public ResultUtil getRecordList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return equipmentServies.getRecordList(page, size);
    }
    /**
     * 获取需要确认的设备列表
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("verify/{page}/{size}")
    public ResultUtil getverifyList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return equipmentServies.getverifyList(page, size);
    }

    /**
     * 取消设备预约
     * @param userId
     * @param equipId
     * @return
     */
    @DeleteMapping("apply/{userId}/{equipId}")
    public ResultUtil cancelApply (@PathVariable("userId") String userId, @PathVariable("equipId") String equipId) {
        return  equipmentServies.cancelApply(userId,equipId);

    }



    /**
     * 归还设备
     * @param userId
     * @param equipId
     * @return
     */
    @PutMapping("back/{userId}/{equipId}")
    public ResultUtil backlEquip (@PathVariable("userId") String userId, @PathVariable("equipId") String equipId) {
        return  equipmentServies.backlEquip(userId,equipId);

    }


    /**
     * 归还设备确认
     * @param userId
     * @param equipId
     * @return
     */
    @PutMapping("backVerify/{userId}/{equipId}")
    public ResultUtil backReview (@PathVariable("userId") String userId, @PathVariable("equipId") String equipId) {
        return  equipmentServies.backReview(userId,equipId);

    }

    /**
     * 取消设备归还
     * @param userId
     * @param equipId
     * @return
     */
    @DeleteMapping("back/{userId}/{equipId}")
    public ResultUtil cancelBack (@PathVariable("userId") String userId, @PathVariable("equipId") String equipId) {
        return  equipmentServies.cancelBack(userId,equipId);

    }
}

